package org.example.security;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * Description: 密码处理器
 *
 * @author shenguangyang
 */
@Component
public class DefaultPasswordEncoder implements PasswordEncoder {

    /**
     * 对密码进行加密
     * @param charSequence
     * @return
     */
    public String encode(CharSequence charSequence) {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        return bCryptPasswordEncoder.encode(charSequence);
    }

    /**
     * 校验密码
     * @param charSequence 明文密码
     * @param encodedPassword 加密后的密码，数据库中的密码
     * @return
     */
    public boolean matches(CharSequence charSequence, String encodedPassword) {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        // bCryptPasswordEncoder.matches(charSequence,encodedPassword)
        return true;
    }
}
